const path = require('path')
// const CompressionPlugin = require("compression-webpack-plugin")
function resolve (dir) {
  return path.join(__dirname, dir)
}
module.exports = {
  chainWebpack: config => {
    config.resolve.alias.set('@', resolve('src'))
    config.module.rule('eslint').use('eslint-loader').options({
      fix: true
    })
    const svgRule = config.module.rule('svg')
    svgRule.uses.clear()
    svgRule.use('vue-svg-loader')
      .loader('vue-svg-loader')
  },
  lintOnSave: 'error',
  css: {
    loaderOptions: {
      less: {
        modifyVars: {
          'primary-color': '#333333',
          'link-color': '#074192',
          'table-row-hover-bg': 'rgba(255,255,84,.07)',
          'table-header-bg': 'rgba(235,235,235,.42)',
          'table-header-color': 'rgba(0,0,0,0.60)',
          'font-size-base': '14px'
        },
        javascriptEnabled: true
      }
    }
  },
  assetsDir: 'static',
  pluginOptions: {
    'style-resources-loader': {
      preProcessor: 'less',
      patterns: [
        // 下面这段是自己加的，根据自己文件的位置来修改
        path.resolve(__dirname, 'src/styles/var.less')
      ]
    }
  },
  // eslint-disable-next-line no-unused-vars
  configureWebpack: config => {
    if (process.env.NODE_ENV === 'production') {
      return {
        // plugins: [
        //   new CompressionPlugin({
        //     test:/\.js$|\.html$|.\css/,
        //     threshold: 10240,
        //     deleteOriginalAssets: false
        //   })
        // ],
        externals: {
          'jquery': '$'
        }
      }
    } else {
      return {
        externals: {
          'jquery': '$'
        }
      }
    }
  },
  devServer: {
    port: 802,
    proxy: {
      '/api': {
        target: 'http://www.qimiaola.com/',
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      }
    },
    disableHostCheck: true
  }
}
